package com.linkage.usercenter.controller;

import cn.hutool.core.util.StrUtil;
import com.linkage.common.base.RequestInfo;
import com.linkage.common.base.ResponseInfo;
import com.linkage.usercenter.pojo.vo.DptInfoVO;
import com.linkage.usercenter.pojo.vo.UserVO;
import com.linkage.usercenter.service.IDepService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/exter")
public class DepManageController {

    private static final Logger logger = LoggerFactory.getLogger(DepManageController.class);


    @Autowired
    private IDepService depService;


    //根据机构查询部门信息
    @RequestMapping(value = "/dpt/getDptList", method = RequestMethod.POST)
    public String getDptList(@RequestBody RequestInfo<Map<String, String>> query){
        String orgCode = query.getBuss().get("paramVar");
        if(StrUtil.isBlank(orgCode)){
            return ResponseInfo.error("机构代码不能为空！").toString();
        }
        List<DptInfoVO> list =  depService.getDptList(orgCode);
        return ResponseInfo.success(list).toString();

    }

    //根据人员手机号查询部门信息
    @RequestMapping(value = "/dpt/getDptListByMobile", method = RequestMethod.POST)
    public String getDptListByMobile(@RequestBody RequestInfo<Map<String, String>> query){
        String userMobile = query.getBuss().get("paramVar");
        if(StrUtil.isBlank(userMobile)){
            return ResponseInfo.error("用户手机号不能为空！").toString();
        }
        List<DptInfoVO> list =  depService.getDptListByMobile(userMobile);
        return ResponseInfo.success(list).toString();
    }

    //根据机构查询人员信息
    @RequestMapping(value = "/dpt/getUsreListByOrgCode", method = RequestMethod.POST)
    public String getUsreListByOrgCode(@RequestBody RequestInfo<Map<String, String>> query){
        String orgCode = query.getBuss().get("paramVar");
        if(StrUtil.isBlank(orgCode)){
            return ResponseInfo.error("机构代码不能为空！").toString();
        }
        List<UserVO> list =  depService.getUsreListByOrgCode(orgCode);
        return ResponseInfo.success(list).toString();
    }

    //根据角色查询人员信息
    @RequestMapping(value = "/role/getUsreListByRoleCode", method = RequestMethod.POST)
    public String getUsreListByRoleCode(@RequestBody RequestInfo<Map<String, String>> query){
        String roleCode = query.getBuss().get("paramVar");
        if(StrUtil.isBlank(roleCode)){
            return ResponseInfo.error("角色代码不能为空！").toString();
        }
        List<UserVO> list =  depService.getUsreListByRoleCode(roleCode);
        return ResponseInfo.success(list).toString();
    }

    /**
     * 根据名称模糊查询
     * @param requestInfo
     * @return
     */
    @PostMapping("/dpt/queryDeptList")
    public String queryDeptList(@RequestBody RequestInfo<DptInfoVO> requestInfo){
        List<DptInfoVO> list = depService.getDptListByName(requestInfo.getBuss().getDptName());
        return ResponseInfo.success(list).toString();
    }

}
